package com.southwind.service.impl;

import com.southwind.VO.BarVO;
import com.southwind.VO.DataVO;
import com.southwind.VO.PieVO;
import com.southwind.entity.Fruit;
import com.southwind.mapper.FruitMapper;
import com.southwind.service.FruitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.southwind.util.DataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author coderchen
 * @since 2021-07-22
 */
@Service
public class FruitServiceImpl extends ServiceImpl<FruitMapper, Fruit> implements FruitService {

    @Autowired
    private FruitMapper fruitMapper;
    @Override
    public BarVO barVOlist() {

        BarVO barVO = new BarVO();
        List<String> names = new ArrayList<>();
        List<DataVO> values = new ArrayList<>();


        /*先查出数据，
        **/
        List<Fruit> fruitList = this.fruitMapper.selectList(null);
        for (Fruit fruit : fruitList) {
            names.add(fruit.getName());
            DataVO dataVO=new DataVO();
            dataVO.setValue(fruit.getSale());
            /*Map<String,String> map=new HashMap<>();
            map.put("color","000000");*/
            dataVO.setItemStyle(DataUtil.createItemStyle(fruit.getSale()));
            /*dataVO.setItemStyle(map);*/
            values.add(dataVO);
        }
        barVO.setNames(names);
        barVO.setValues(values);

        /* 再转换vo */
        return barVO;
    }

    @Override
    public List<PieVO> pioVOlist() {
        List<PieVO> pieVOList = new ArrayList<>();
        List<Fruit> fruits=this.fruitMapper.selectList(null);
        for (Fruit fruit : fruits) {
            PieVO pieVO = new PieVO();
            pieVO.setValue(fruit.getSale());
            pieVO.setName(fruit.getName());
            pieVO.setItemStyle(DataUtil.createItemStyle(fruit.getSale()));
            pieVOList.add(pieVO);
        }
        return  pieVOList;
    }
}
